﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Assets.Scripts.Game.Event;
using Assets.Scripts.Game.GameObj;

namespace Assets.Scripts.Game.AI
{

    /**   
     * 暂时使用一个状态
     * 
     */

    public class StateMachine
    {
        private readonly Characater _owner;

        public StateMachine(Characater owner)
        {
            _owner = owner;
            
        }
        /**
         * 初始化
         */
        public void Init()
        {
            
        }

        /**
         * 设定状态
         */         
        protected void SetCurState(State state)
        {
            _curState = state;
        }

        private State _curState;
        /***
         * 判定是否处于当前状态
         */
        public bool IsState(AiStateType type)
        {
            return type == _curState.GetAiStateType();
        }

        /**
         * 状态切换
         */
        public bool ChangeState(State state)
        {
            if (state == null) 
                return  false;

            //需要判定是否可以切换？
            SetCurState(state);
            return true;
        }


        /***
         * 更新
         */
        public void Update(float dt)
        {
            if (_curState == null)
            {
                return;
            }

            _curState.OnUpdate(_owner,dt);
        }


        public void ProcEvent(BaseEvent command)
        {
            if (_curState == null)
            {
                return;
            }

            _curState.OnEvent(_owner,command);
        }




    }



}
